package com.asia5b.a5mall.goods.adapter

import androidx.core.content.ContextCompat
import android.widget.TextView
import com.asia5b.a5mall.goods.R
import com.asia5b.a5mall.middleware.model.goods.Goods2SpecModel
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/1/18.
 */
class SpecAdapter(list: ArrayList<Goods2SpecModel>) :
        BaseQuickAdapter<Goods2SpecModel, BaseViewHolder>(R.layout.item_sku_value_adapter, list) {

    init {
        addChildClickViewIds(R.id.tv_sku_value)
    }

    override fun convert(helper: BaseViewHolder, item: Goods2SpecModel) {
        helper.setText(R.id.tv_sku_value, item.spec_value)

        val tv_sku_value = helper.getView<TextView>(R.id.tv_sku_value)
        var bgDrawableRes: Int
        var txColor:Int
        /*
        选中  背景色   #0091FF  0.1  字体色：0091FF


没有选中  背景色  #F5F5F5  字体色： #333333

加入购物车  背景色 #2FA6FD   字体色  白色
         */
        when (item.bgState) {
            0 -> {
                bgDrawableRes = R.drawable.shape_sku_normal
                txColor=R.color.common_text_black
            }
            1 -> {
                bgDrawableRes = R.drawable.shape_sku_press
                txColor=R.color.common_text_blue
            }
            else -> {
                bgDrawableRes = R.drawable.shape_sku_unenable
                txColor=R.color.common_text_gray
            }
        }
        tv_sku_value.setBackgroundResource(bgDrawableRes)
        tv_sku_value.setTextColor(ContextCompat.getColor(context,txColor))

    }
}